package org.styx.seata.tcc.account.tcc;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

import java.math.BigDecimal;

/**
 * @date 2021/10/9
 * @auther uranus
 */
@LocalTCC
public interface AccountTccAction {

    /**
     * 准备减少账户
     *
     * @param context 上下文
     * @param userId  用户id
     * @param money   钱
     * @return boolean
     */
    @TwoPhaseBusinessAction(name="accountTccAction")
    boolean prepareDecreaseAccount(BusinessActionContext context,
                                   @BusinessActionContextParameter(paramName
                                           = "userId") Long userId,
                                   @BusinessActionContextParameter(paramName
                                           = "money") BigDecimal money);

    /**
     * 提交
     *
     * @param context 上下文
     * @return boolean
     */
    boolean commit(BusinessActionContext context);

    /**
     * 回滚
     *
     * @param context 上下文
     * @return boolean
     */
    boolean rollback(BusinessActionContext context);
}
